package edu.scmu.controller;

import edu.scmu.pojo.User;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import java.time.LocalDateTime;
import java.util.List;

@RestController
//@Controller
public class RequestController {

    @RequestMapping("/simplePojo")
//    @ResponseBody
    public String simplePojo(User user) {
        System.out.println("name:" + user.getName() + ",age:" + user.getAge());
        return "ok";
    }


    @RequestMapping("/complexPojo")
    public String complexPojo(User user) {
        System.out.println("name:" + user.getName() + ",age:" + user.getAge() + ",Province:" + user.getAddress().getProvince());
        return "ok";
    }

    @RequestMapping("/register")
    public String register(String[] interests) {
        for(String str: interests){
            System.out.println(str);
        }
        return "ok";
    }

    @RequestMapping("/register2")
    public String register(@RequestParam List<String> interests) {
        for(String str: interests){
            System.out.println(str);
        }
        return "ok";
    }

    @RequestMapping("/birthday")
    public String birthday(@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime date) {
        System.out.println(date);
        return "ok";
    }

    @RequestMapping("/jsonParam")
    public String jsonParam(@RequestBody User user) {
        System.out.println(user);
        return "ok";
    }


        //路径参数
        @RequestMapping("/path/{name}/{age}")
        public String pathParam(@PathVariable String name, @PathVariable Integer age){
            System.out.println(name + "," + age);
            return "OK";
        }
}
